package cn.amebius.simpledocker.mapper;

import cn.amebius.simpledocker.controller.request.AddDockerClientRequest;
import cn.amebius.simpledocker.controller.request.UpdateDockerClientRequest;
import cn.amebius.simpledocker.entity.po.DockerPo;
import cn.hutool.core.date.DateTime;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * tb_docker的一些操作
 * @author 阿伟
 * @date 2023/7/28 20:24
 */

@Mapper
public interface DockerMapper {

    @Select("select * from tb_docker where deleted = 0")
    List<DockerPo> selectAll();

    @Insert("insert into tb_docker (name,host,port,username,password,type,create_time,deleted) " +
            "values (#{adcr.name},#{adcr.host},#{adcr.port},#{adcr.username},#{adcr.password}," +
            "#{adcr.type},#{createTime},0)")
    void insertOne(@Param("adcr") AddDockerClientRequest adcr,@Param("createTime") DateTime createTime);


    @Select("select * from tb_docker where name = #{name}")
    DockerPo selectByName(String name);

    @Select("select * from tb_docker where host = #{host} and port = #{port}")
    DockerPo selectByHostAndPort(@Param("host") String host,@Param("port") String port);

    @Select("select * from tb_docker where id = #{key}")
    DockerPo selectById(Integer key);


    @Update("update tb_docker set name = #{udcr.name}, host = #{udcr.host}, port = #{udcr.port}," +
            "username = #{udcr.username}, password = #{udcr.password}, type = #{udcr.type}" +
            "where id = #{udcr.key}")
    void updateById(@Param("udcr") UpdateDockerClientRequest udcr);

    @Update("update tb_docker set deleted = 1 where id = #{key}")
    void updateDeletedById(@Param("key") Integer key);
}
